package chaos.util;

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.Enumeration;
import java.util.Vector;

public class AbsPathResourceManager implements ResourceManager {
	File file;
	String path;
	Vector streams;
	
	public AbsPathResourceManager(String path) {
		this.path = path;
	}

	public void init() throws Exception {
		file = new File(path);
		streams = new Vector();
	}

	public void close() {
		Enumeration enu = streams.elements();
		while(enu.hasMoreElements()) {
			InputStream ins = (InputStream)enu.nextElement();
			try {
				ins.close();
			} catch (Exception e) {
			}
		}
	}

	public InputStream getInputStream(String path) {
		File rFile = new File(file.getAbsolutePath()+"/"+path);
		if(!rFile.isFile()) return null;
		try {
			InputStream ins = new FileInputStream(rFile);
			streams.add(ins);
			return ins;
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}
}
